import { ref } from "vue";

export const useCounter = (num) => {
  const count = ref(num);
  const increment = () => {
    count.value++;
  };
  const decrement = () => {
    count.value--;
  };
  return [count, increment, decrement];
};

export const useTodolist = () => {
  const value = ref("");
  const list = ref([
    {
      id: 1,
      name: "zhangmou",
    },
  ]);
  const add = () => {
    list.value.push({
      id: new Date().getTime(),
      name: value.value,
    });
    value.value = "";
  };
  const remove = (id) => {
    list.value = list.value.filter((item) => item.id !== id);
  };

  return [value, list, add, remove];
};
